import EGlobal from "./EGlobal"

//地图编辑控制器
cc.Class({
    extends: cc.Component,
    mapTouchstart(event) {
        let wordPos = event.getLocation();
        let locationPos = EGlobal.mapEdit.P_editNode.convertToNodeSpaceAR(wordPos)
        let selectBlockIndex = EGlobal.mapEdit.getCurBlock(wordPos)
        if (selectBlockIndex != null) {
            EGlobal.mapEdit.moveImage.getComponent(cc.Sprite).spriteFrame = EGlobal.mapEdit.P_blockAtllas.getSpriteFrames()[selectBlockIndex]
            EGlobal.mapEdit.moveImage.setPosition(locationPos)
            EGlobal.mapEdit.moveImage.active = true
        }
    },
    mapTouchmove(event) {
        let wordPos = event.getLocation();
        let locationPos = EGlobal.mapEdit.P_editNode.convertToNodeSpaceAR(wordPos)
        EGlobal.mapEdit.moveImage.setPosition(locationPos)
    },
    mapTouchend(event) {
        let wordPos = event.getLocation();
        let selectViewMapIndex = EGlobal.mapEdit.getCurMapBlock(wordPos)
        if (selectViewMapIndex != null) {
            EGlobal.mapEdit.viewMapItems[selectViewMapIndex[1]][selectViewMapIndex[0]].getComponent(cc.Sprite).spriteFrame = EGlobal.mapEdit.moveImage.getComponent(cc.Sprite).spriteFrame
            ///selectViewMapIndex[1]][selectViewMapIndex[0]   数组第一个读的肯定是Y 然后再读X
        }
        EGlobal.mapEdit.moveImage.active = false
    },
    mapTouchcancel() {
        EGlobal.mapEdit.moveImage.active = false
    }
});